import cv2
# 形态学梯度 = 原图 - 腐蚀
img = cv2.imread('./1.jpg')
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
gradient = cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel)
cv2.imshow('img', img)
cv2.imshow('gradient', gradient)
cv2.waitKey(0)